package com.example.util;

import com.example.models.Tower;

/**
 * A map cell.
 * This class holds the model in the current cell, a path node and 
 * tower ranges.
 * @authors Itay Sorani, Nadav Ziv, Yonathan Zarsky
 */
public class MapCell {
	
	// maximum number of tower ranges per cell
	private static final int MAX_NUMBER_OF_RANGES_PER_CELL = 15;
	// the model which this cell holds
	private Figure model;
	// the towers which this cell is within their boundaries. 
	private Tower[] towersInRange;
	// // the number of towers which this cell is within their boundaries. 
	private int numberOfRanges;
	// the Path Node which this cell holds
	private PathNode pathNode;
	
	
	/**
	 * Constructs a new map cell and initializing its variables to null. 
	 */
	public MapCell(Figure model) {
		setModel(model);
		towersInRange = new Tower[MAX_NUMBER_OF_RANGES_PER_CELL];
		numberOfRanges = 0;
		setPathNode(null);
	}
	
	/**
     * sets the figure which this cell holds.
     */
	public void setModel(Figure model) {
		this.model = model;
	}
	
	/**
     * returns the figure which this cell holds.
     */
	public Figure getModel() {
		return model;
	}

	/**
     * adds a tower which this cell is within their boundaries.
     */
	public void addTowerInRange (Tower tower) {
		this.towersInRange[numberOfRanges] = tower;
		numberOfRanges++;
	}
	
	/**
     * removes a tower which this cell is within its boundaries.
     */
	public void removeTowerInRange (Tower tower) {
		for (int i = 0; i < numberOfRanges; i++) {
			if (towersInRange[i].equals(tower)) {
				towersInRange[i] = towersInRange[numberOfRanges - 1];
				towersInRange[numberOfRanges - 1] = null;
			}
		}
		this.numberOfRanges--;
	}

	/**
     * sets the path node which this cell holds.
     */
	public void setPathNode(PathNode pathNode) {
		this.pathNode = pathNode;
	}

	/**
     * returns the path node which this cell holds.
     */
	public PathNode getPathNode() {
		return pathNode;
	}
	
	/**
     * returns the towers which this cell is within their boundaries.
     */
	public Tower[] getTowersInRange() {
		return towersInRange;
	}
	
	/**
     * returns the number of towers which this cell is within their boundaries.
     */
	public int getNumberOfRangeNodes() {
		return this.numberOfRanges;
	}
	
}
